<?php
session_start();
require_once '../classes/globalvar.php';
/*Check login or not*/
if($_GET['type']=='log')
{
	if(isset($_SESSION['aususrrealid']))
	{
		echo '1_'.$_SESSION['aususrrealid'];
	}
	else
	{
		echo '2';
	}
}
elseif ($_GET['type']=='c')
{
	$tempArray = array();
	$tempArray['1'] = 'ACT';
	$tempArray['2'] = 'NSW';
	$tempArray['3'] = 'NT';
	$tempArray['4'] = 'QLD';
	$tempArray['5'] = 'SA';
	$tempArray['6'] = 'TAS';
	$tempArray['7'] = 'VIC';
	$tempArray['8'] = 'WA';
	$tempArray['9'] = 'oversea';
	
	$citySelectId = $_GET['cy'];
	if(key_exists($citySelectId,$tempArray))
	{	
		if($_SESSION['myCityChoice']!=$citySelectId) /*if the city defers the old one*/
		{
		/* Deleted by Liang, don't change the session here!
			@session_unregister('myCityChoice');
			@session_register('myCityChoice');
			$_SESSION['myCityChoice'] = $citySelectId;
			setcookie('iCity','',time()-3600*24*7,'/');
			setcookie('iCity',$citySelectId,time()+3600*24,'/');
			*/	
		}
	}
	else /*Can not found in the array*/
	{
		header('location:'.ERROR_404);
		exit;
	}

	if(file_exists('./hello-'.$tempArray[$citySelectId].'.html'))
	{
		$createdTimeBefore = filectime('./hello-'.$tempArray[$citySelectId].'.html');
		$nowadays = time();
		$diff = $nowadays - $createdTimeBefore;
		if($diff > 86400)
		{
			header('location:'.WELCOME_COMPASS_HOME.'/navurl/nav.php?buildCity='.$citySelectId);
			exit;
		}
		else
		{
			header('location:'.WELCOME_COMPASS_HOME.'/navurl/hello-'.$tempArray[$citySelectId].'.html?'.time());
			exit;
		}	
	}
	else
	{
		header('location:'.WELCOME_COMPASS_HOME.'/navurl/nav.php?buildCity='.$citySelectId);
		exit;
	}
	
}